package controller;

import exception.SomeException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/3/10 13:32
 * Version:1.0-SNAPSHOT
 */
@Controller
@RequestMapping(value = "/hello")
public class HelloAnnotationController {

//    @RequestMapping("/sayHello")
//    @RequestMapping("/f1")
//    @RequestMapping({"/f1","/sayHello"})
    @GetMapping
    public ModelAndView f1(){
        ModelAndView mav = new ModelAndView();
        mav.addObject("msg","Hello Annotation");
        mav.setViewName("hello");
        return mav;
    }

    @PostMapping
    public ModelAndView f2(){
        ModelAndView mav = new ModelAndView();
        mav.addObject("msg","Hello POST");
        mav.setViewName("hello");
        return mav;
    }

    @RequestMapping("/f3")
    public void f3() throws SomeException {
        System.out.println("HelloAnnotationController.f3");
        throw new SomeException("执行Hello中的f3遇到了异常");
    }

}
